#include <windows.h>
#include <stdio.h>

#include "CAsyncSocket.hpp"


BOOL CAsyncSocket::Connect( LPCTSTR lpszHostAddress, UINT nHostPort )
{
    struct sockaddr_in sin;
    struct hostent *host = gethostbyname( lpszHostAddress );

    memcpy(&sin.sin_addr.s_addr, host->h_addr, host->h_length);

    sin.sin_family = AF_INET;
    sin.sin_port = htons( nHostPort );

    return( connect(this->m_hSocket, (struct sockaddr *)&sin, sizeof(sin)) > 0);
}

int CAsyncSocket::Receive( void* lpBuf, int nBufLen, int nFlags )
{
    return recv( this->m_hSocket, (char *)lpBuf, nBufLen, nFlags );
}

int CAsyncSocket::Send( const void* lpBuf, int nBufLen, int nFlags )
{
    return send( this->m_hSocket, (const char *)lpBuf, nBufLen, nFlags );
}

void CAsyncSocket::Close()
{
    closesocket( this->m_hSocket );
}
